<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
</head>
<script>
    $(function () {
        $(".inputBtn").click(function () {
            // 处理数据缓存的问题
            $("#editForm")[0].reset();
            $("#coverImg").removeAttr('src');
            var json=$(this).data("json")
            if(json){
                //回显数据
                $("input[name=id]").val(json.id)
                $("input[name=name]").val(json.name)
                $("input[name=mark]").val(json.mark)
                $("input[name=price]").val(json.price)
                $("select[name='state']").val(json.state);
                $("select[name='kind']").val(json.kind);

                $("#coverImg").attr('src', json.coverUrl);
                $("input[name='coverUrl']").val(json.coverUrl);
            }
            $("#updateModal").modal("show")
        });
        //提交模态框中的表单问题
        $(".submitBtn").click(function () {
            $("#editForm").ajaxSubmit(function (data) {
                handleResult(data);
            });
        });
    })
</script>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="commodity"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/commodity/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>商品的状态:</label>
                    <select class="form-control" name="state" id="state">
                        <option value="-1">全部</option>
                        <option value="3">售卖中</option>
                        <option value="2">缺货中</option>
                        <option value="1">已下架</option>
                    </select>
                    <script>
                        $("#state").val(${qo.state!})
                    </script>
                </div>
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入标题">
                </div>
                <button class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>商品名称</th>
                    <th>图片</th>
                    <th>需要的积分</th>
                    <th>价格</th>
                    <th>类别</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.name}</td>
                        <td><img src="${entity.coverUrl}" width="40px"></td>
                        <td>${entity.mark}</td>
                        <td>${entity.price}</td>
                        <td>${entity.kindName}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/commodity/saveOrUpdate.do" method="post" id="editForm">
                    <!--游记推荐的id-->
                    <input type="text" name="id" hidden>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="100%"/>
                            <input type="hidden" name="coverUrl">
                            <input type="file" class="form-control" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品需要花费的积分：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="mark">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品价格：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="price">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品种类：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="kind">
                                <option value="1">书籍类</option>
                                <option value="2">衣服类</option>
                                <option value="3">食品类</option>
                                <option value="4">智能类</option>
                                <option value="5">未定义类</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="3">售卖中</option>
                                <option value="2">缺货中</option>
                                <option value="1">已下架</option>
                            </select>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>


</body>
</html>